<script type="text/javascript">
	var $agendaadd_content = $("#agendaadd_content");

	$(document).ready(function () {
		var theme = 'fresh';
		$('.field_input').addClass('jqx-input');
		$('.field_input').addClass('field');
		$('.field_input').addClass('jqx-rc-all');

		var agendaadd_save = $("#agendaadd_save");
		var agendaadd_cancel = $("#agendaadd_cancel");
		var agendapost_id = $("#agendapost_id");
		var agendapost_task = $("#agendapost_task");
		var agendapost_agenda = $("#agendapost_agenda");
		var agendapost_tanggal = $("#agendapost_tanggal");
		var agendapost_jam = $("#agendapost_jam");
		var agendapost_tempat = $("#agendapost_tempat");
		var agendapost_keterangan = $("#agendapost_keterangan");
		var agendapost_publish = $("#agendapost_publish");

		agendaadd_save.jqxButton({ theme : theme, width : '70px', height : '18px' });
		agendaadd_cancel.jqxButton({ width : '70px' , height : '18px' ,theme : theme });

		agendapost_tanggal.jqxDateTimeInput({
			formatString : 'dd-MM-yyyy',
			width : 150,
			height : 25,
			theme : theme,
			enableAbsoluteSelection: true
		});
		agendapost_keterangan.wysibb();
		/* function */
		agendaadd_cancel.click(function(){
			$('#mainpanelcontent').empty();
			$('<img src="./images/loader.gif" style="margin:50px auto auto 390px;">').appendTo('#contents');
			$('#mainpanelcontent').load('index.php/c_agenda/agenda_load');
		});
		agendaadd_save.click(function(){
			var id = "";
			var agenda = "";
			var tanggal = "";
			var jam = "";
			var tempat = "";
			var keterangan = "";
			var publish = "";
			var task = "";

			id = agendapost_id.val();
			agenda = agendapost_agenda.val();
			tanggal = agendapost_tanggal.jqxDateTimeInput('getDate');
			tanggal = $.jqx.dataFormat.formatdate(tanggal, 'dd-MM-yyyy');
			jam = agendapost_jam.val();
			tempat = agendapost_tempat.val();
			keterangan = agendapost_keterangan.htmlcode();
			task = agendapost_task.val();

			if (agendapost_publish.prop("checked")==true) {
				publish = 'y';
			}else{
				publish = 't';
			}

			if(task == ""){
				task = "create";
			}
			$.ajax({
				type : 'POST',
				url : 'index.php/c_agenda/agenda_save',
				data : {
					id : id,
					agenda : agenda,
					tanggal : tanggal,
					jam : jam,
					tempat : tempat,
					publish : publish,
					keterangan : keterangan,
					task : task
				},success : function(msg){
					var result = eval(msg);
					switch(result){
						case 1:
							$('#mainpanelcontent').empty();
							$('<img src="./images/loader.gif" style="margin:50px auto auto 390px;">').appendTo('#contents');
							$('#mainpanelcontent').load('index.php/c_agenda/agenda_load');
							alert("Data berhasil disimpan");
							break;
						default:
							alert("Data gagal disimpan");
							break;
					}
				}
			});
		});

		<?php
			if(isset($dataDetail)){
		?>
			agendapost_id.val('<?php echo $dataDetail->id; ?>');
			agendapost_agenda.val('<?php echo $dataDetail->agenda; ?>');
			var arr_tgl = '<?php echo $dataDetail->tanggal; ?>'.split('-');
			var set_tgl = new Date(arr_tgl[0], (arr_tgl[1] - 1), arr_tgl[2]);
			agendapost_tanggal.jqxDateTimeInput('setDate', set_tgl);
			agendapost_jam.val('<?php echo $dataDetail->jam; ?>');
			agendapost_keterangan.htmlcode(<?php echo json_encode($dataDetail->keterangan); ?>);
			agendapost_tempat.val('<?php echo $dataDetail->tempat; ?>');
			agendapost_task.val('update');
		<?php

				if($dataDetail->publish=='y'){
					echo "agendapost_publish.prop(\"checked\", true);";
				}

			}
		?>

	});

</script>
<!-- Begin content -->
<div class="modal_header">
		<span>Agenda Form</span>
	</div>
<div class="modal_content">
<div id="agendaadd_content">
	<input type="hidden" id="agendapost_id">
	<input type="hidden" id="agendapost_task">
	<form action="" method="post" >
		<p>
			<label>Agenda:</label><br/>
			<input type="text" id="agendapost_agenda" class="field_input" style="width:500px"/>
		</p>
		<br/>
		<p>
			<label>Tanggal:</label><br/>
			<div id="agendapost_tanggal"></div>
		</p>
		<br/>
		<p>
			<label>Jam:</label><br/>
			<input type="text" id="agendapost_jam" class="field_input" name="datepicker" style="width:100px"/>
		</p>
		<br/>
		<p>
			<label>Tempat:</label><br/>
			<input type="text" id="agendapost_tempat" class="field_input" style="width:300px"/>
		</p>
		<br/>
		<p>
			<label>Keterangan:</label><br/>
			<textarea rows="7" cols="50" id="agendapost_keterangan" class="wysiwyg" ></textarea>
		</p>
		<br/>
		<p>
			<input type="checkbox" class="checkbox"  id="agendapost_publish"> <label for="cbdemo1">Publish</label>
		</p>
		<br/><br/>
		<p>
			<table align="left">
				<tr align="left">
					<td>
						<div id='agendaadd_save'>
						<img style='float: left; margin: 0px;' src='./images/icons/save.gif' />
						<div style='float: left; margin-left: 4px;'>Simpan</div>
					</div>
					</td>
					<td>
						<div id='agendaadd_cancel'>
						<img style='float: left; margin: 0px;' src='./images/icons/cross.gif' />
						<div style='float: left; margin-left: 4px;'>Cancel</div>
					</div>
					</td>
				</tr>
			</table>
		</p>
		<p>&nbsp;</p>
	</form>
</div>
</div>
<!-- End left column window -->